<?php

class IepluginsController extends CController{

	public function actionPlugin(){
		setcookie('name','name',1000*60,'/');
		dbg($_COOKIE);
		if(Yii::app()->user->isGuest){
			NC::json('1','pease login');
		}
		NC::json('2','sucess');
	}
	public function actionTest(){
		//session_start();
		//dbg($_SESSION);
		
	}

	public function actionisLogin(){

		if(Yii::app()->user->isGuest){
			echo 'false';
		}else
			echo 'true';
	}

	public function actionLogin(){

		$email = NC::_g('email','');
		$password = NC::_g('password','');
		$login = new AccountForm('login');
		$login->email = $email;
		$login->password = md5($password);

		if($login->login()){
			//登录成功
			$username=Yii::app()->user->name;
			echo $username.'#'.md5($password);
		}else{
			echo 'ErrorLogin';
			//login error
		}

	}
	public function euc_cnToUtf8($str){
		$encode = mb_detect_encoding($str,array('ASCII','GB2312','GBK','UTF-8','BIG5')); 
		iconv($encode,'UTF-8',$str);
		return $str;
	}
	public function actionAdd(){
		$news = new News;

		$news->site_title = iconv('GB2312','UTF-8',NC::_g('title',''));
		$news->news_desc = iconv('GB2312','UTF-8',NC::_g('description',''));
		$news->news_tag = iconv('GB2312','UTF-8',NC::_g('tag',''));
		$news->link_url = trim(iconv('GB2312','UTF-8',NC::_g('url','')));
		
		$validateUrlUnique = News::validateUrlUnique($news->link_url);

		if($validateUrlUnique){
			echo 'repeat';exit;
		}

		if($news->createNews($news)){
			$news_id = $news->primaryKey;
				//写入到一个文件中，让其去自动抓取默认照片
			CacheFile::cacheThumb($news_id,$news->link_url);
			echo 'sucess';exit;
		}else{
			echo 'error';exit;
		}
	}
}

?>